home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Mud 4.0 / rc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-23  |  7.7 KB  |  289 lines  |  [TEXT/MPS ]

  1. #include "config.h"
  2.  
  3. #include <Types.h>
  4. #include <Resources.h>
  5. #include <Packages.h>
  6. #include <sys/types.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include "lint.h"
  11. #include "interpret.h"
  12. #include "exec.h"
  13. #include "object.h"
  14. #include "comm.h"
  15. #include "rc.h"
  16. #include "mac.h"
  17.  
  18. #define CONFIG_SIZE        40
  19.  
  20. /*
  21.  * Do not change the values here; if you want to change something,
  22.  * do it in the startup script.
  23.  */
  24.  
  25. struct config configs[CONFIG_SIZE];
  26.  
  27. static void set_def_configs()
  28. {
  29.     configs[0].cf_name = "Mud host name";
  30.     configs[0].cf_type = CF_STR;
  31.     configs[0].u.cf_int = "MacMud";
  32.  
  33.     configs[1].cf_name = "Master object file";
  34.     configs[1].cf_type = CF_STR;
  35.     configs[1].u.cf_str = "/obj/master";
  36.  
  37.     configs[2].cf_name = "Simul_efun file";
  38.     configs[2].cf_type = CF_STR;
  39.     configs[2].u.cf_str = "/obj/simul_efun";
  40.  
  41.     configs[3].cf_name = "Preload file";
  42.     configs[3].cf_type = CF_STR;
  43.     configs[3].u.cf_str = "room/init_file";
  44.  
  45.     configs[4].cf_name = "Swap file";
  46.     configs[4].cf_type = CF_STR;
  47.     configs[4].u.cf_str = "MacMud_swap_";
  48.  
  49.     configs[5].cf_name = "Forced include file";
  50.     configs[5].cf_type = CF_STR;
  51.     configs[5].u.cf_str = "/include/standard.h";
  52.  
  53.     configs[6].cf_name = "Mudlib directory";
  54.     configs[6].cf_type = CF_STR;
  55.     configs[6].u.cf_str = "";
  56.  
  57.     configs[7].cf_name = "Player directory";
  58.     configs[7].cf_type = CF_STR;
  59.     configs[7].u.cf_str = "players";
  60.  
  61.     configs[8].cf_name = "Domain directory";
  62.     configs[8].cf_type = CF_STR;
  63.     configs[8].u.cf_str = "players";
  64.  
  65.     configs[9].cf_name = "Default castle file";
  66.     configs[9].cf_type = CF_STR;
  67.     configs[9].u.cf_str = "room/def_castle.c";
  68.  
  69.     configs[10].cf_name = "Default workroom file";
  70.     configs[10].cf_type = CF_STR;
  71.     configs[10].u.cf_str = "room/def_workroom.c";
  72.  
  73.     configs[11].cf_name = "Admin log files";
  74.     configs[11].cf_type = CF_STR;
  75.     configs[11].u.cf_str = "";
  76.  
  77.     configs[12].cf_name = "Maximum local log size";
  78.     configs[12].cf_type = CF_INT;
  79.     configs[12].u.cf_int = 50000;
  80.  
  81.     configs[13].cf_name = "Maximum global log size";
  82.     configs[13].cf_type = CF_INT;
  83.     configs[13].u.cf_int = 1000000;
  84.  
  85.     configs[14].cf_name = "Maximum read_file size";
  86.     configs[14].cf_type = CF_INT;
  87.     configs[14].u.cf_int = 50000;
  88.  
  89.     configs[15].cf_name = "Cleanup time";
  90.     configs[15].cf_type = CF_INT;
  91.     configs[15].u.cf_int = 7200;
  92.  
  93.     configs[16].cf_name = "Swap time";
  94.     configs[16].cf_type = CF_INT;
  95.     configs[16].u.cf_int = 900;
  96.  
  97.     configs[17].cf_name = "Reset time";
  98.     configs[17].cf_type = CF_INT;
  99.     configs[17].u.cf_int = 3600;
  100.  
  101.     configs[18].cf_name = "Evaluator stack size";
  102.     configs[18].cf_type = CF_INT;
  103.     configs[18].u.cf_int = 1000;
  104.  
  105.     configs[19].cf_name = "Compiler stack size";
  106.     configs[19].cf_type = CF_INT;
  107.     configs[19].u.cf_int = 200;
  108.  
  109.     configs[20].cf_name = "Maximum bitstring size";
  110.     configs[20].cf_type = CF_INT;
  111.     configs[20].u.cf_int = 1200;
  112.  
  113.     configs[21].cf_name = "Living hash table size";
  114.     configs[21].cf_type = CF_INT;
  115.     configs[21].u.cf_int = 100;
  116.  
  117.     configs[22].cf_name = "Port number";
  118.     configs[22].cf_type = CF_INT;
  119.     configs[22].u.cf_int = 8888;
  120.  
  121.     configs[23].cf_name = "Maximum local variables";
  122.     configs[23].cf_type = CF_INT;
  123.     configs[23].u.cf_int = 20;
  124.  
  125.     configs[24].cf_name = "Maximum evaluation cost";
  126.     configs[24].cf_type = CF_INT;
  127.     configs[24].u.cf_int = 100000;
  128.  
  129.     configs[25].cf_name = "Maximum array size";
  130.     configs[25].cf_type = CF_INT;
  131.     configs[25].u.cf_int = 1000;
  132.  
  133.     configs[26].cf_name = "Maximum players";
  134.     configs[26].cf_type = CF_INT;
  135.     configs[26].u.cf_int = 50;
  136.  
  137.     configs[27].cf_name = "Hash table size";
  138.     configs[27].cf_type = CF_INT;
  139.     configs[27].u.cf_int = 2203;
  140.  
  141.     configs[28].cf_name = "Object hash table size";
  142.     configs[28].cf_type = CF_INT;
  143.     configs[28].u.cf_int = 1009;
  144.  
  145.     configs[29].cf_name = "Maximum transfer bytes";
  146.     configs[29].cf_type = CF_INT;
  147.     configs[29].u.cf_int = 10000;
  148.  
  149.     configs[30].cf_name = "Maximum string length";
  150.     configs[30].cf_type = CF_INT;
  151.     configs[30].u.cf_int = 131072;
  152.  
  153.     configs[31].cf_name = "Reserved memory size";
  154.     configs[31].cf_type = CF_INT;
  155.     configs[31].u.cf_int = 0;
  156.  
  157.     configs[32].cf_name = "Maximum trace depth";
  158.     configs[32].cf_type = CF_INT;
  159.     configs[32].u.cf_int = 20;
  160.  
  161.     configs[33].cf_name = "Debug level";
  162.     configs[33].cf_type = CF_INT;
  163.     configs[33].u.cf_int = 0;
  164.  
  165.     configs[34].cf_name = "Idle level";
  166.     configs[34].cf_type = CF_INT;
  167.     configs[34].u.cf_int = 0;
  168.  
  169.     configs[35].cf_name = "Trace compilations";
  170.     configs[35].cf_type = CF_INT;
  171.     configs[35].u.cf_int = 0;
  172.  
  173.     configs[36].cf_name = "Restart mud automatically";
  174.     configs[36].cf_type = CF_INT;
  175.     configs[36].u.cf_int = 0;
  176.  
  177.     configs[37].cf_name = "Required runtime memory";
  178.     configs[37].cf_type = CF_INT;
  179.     configs[37].u.cf_int = 1024000;
  180.  
  181.     configs[38].cf_name = "Multi user";
  182.     configs[38].cf_type = CF_INT;
  183.     configs[38].u.cf_int = 0;
  184.  
  185.     configs[39].cf_name = "What message ?";
  186.     configs[39].cf_type = CF_STR;
  187.     configs[39].u.cf_int = "What ?\n";
  188. }
  189.  
  190. void read_config(void)
  191. {
  192.     short i;
  193.     long len;
  194.     char *s;
  195.     char *conf;
  196.     Handle confHdl;
  197.  
  198.     set_def_configs();
  199.     confHdl = GetResource('CONF',0);
  200.     if (confHdl) {
  201.         HLock(confHdl);
  202.         conf = (char *)(*confHdl);
  203.         for (i = 0; i < CONFIG_SIZE; i++) {
  204.             if (configs[i].cf_type == CF_STR) {
  205.                 len = strlen(conf);
  206.                 if ((s = malloc(len+1))) {
  207.                     memcpy(s, conf, len);
  208.                     s[len] = '\0';
  209.                     configs[i].u.cf_str = s;
  210.                 }
  211.                 conf += len + 1;
  212.             } else if (configs[i].cf_type == CF_INT) {
  213.                 configs[i].u.cf_int = *((long *)conf);
  214.                 conf += sizeof(long);
  215.             }
  216.         }
  217.         HUnlock(confHdl);
  218.         ReleaseResource(confHdl);
  219.     }
  220. }
  221.  
  222. /*
  223.  * Init some global arrays, formerly declared with a predefined
  224.  * value from config.h as their size. They must now be malloc'ed.
  225.  * This is not very beautiful, but the advantage is, that everything
  226.  * is easily, dynamically tuned.
  227.  */
  228.  
  229. extern int gRuntimeMem;
  230. extern char **local_names;                    /* prelang.y */
  231. extern unsigned short *type_of_locals;        /* prelang.y */
  232. extern struct svalue *start_of_stack;        /* interpret.c */
  233. extern int *comp_stack;                        /* prelang.y */
  234. extern struct object **hashed_living;        /* object.c */
  235. extern struct interactive **all_players;    /* comm1.c */
  236. extern struct control_stack *control_stack;    /* interpret.c */
  237. extern long time_to_swap;                    /* main.c */
  238. extern int port_number;                        /* main.c */
  239. extern int d_flag;                            /* main.c */
  240. extern int t_flag;                            /* main.c */
  241. extern int comp_flag;                        /* main.c */
  242. #ifdef NLHACK
  243. extern char **log_admin_files;            /* nlhack.c */
  244. extern int nr_log_admin_files;
  245. #endif
  246.  
  247. void init_global_configs()
  248. {
  249. #ifdef NLHACK
  250.     char *p, n = 0, *start;
  251. #endif
  252.  
  253.     gRuntimeMem = RUNTIME_MEMORY;
  254.     local_names = (char **) calloc(MAX_LOCAL, sizeof (char *));
  255.     type_of_locals = (unsigned short *)
  256.     calloc(MAX_LOCAL, sizeof (unsigned short));
  257.     start_of_stack = (struct svalue *)
  258.     calloc(EVALUATOR_STACK_SIZE, sizeof (struct svalue));
  259.     comp_stack = (int *) calloc(COMPILER_STACK_SIZE, sizeof (int));
  260.     hashed_living = (struct object **)
  261.     calloc(LIVING_HASH_SIZE, sizeof (struct object *));
  262.     all_players = (struct interactive **)
  263.     calloc(MAX_PLAYERS, sizeof (struct interactive *));
  264.     control_stack = (struct control_stack *)
  265.         calloc(MAX_TRACE, sizeof(struct control_stack));
  266.     time_to_swap = (long) TIME_TO_SWAP;
  267.     port_number = PORTNO;
  268. #ifdef NLHACK
  269.     n = 0;
  270.     if (LOG_ADMIN_FILES && strlen(LOG_ADMIN_FILES)) {
  271.     p = LOG_ADMIN_FILES;
  272.     do {
  273.         n++;
  274.     } while (p = strchr(p + 1, ','));
  275.     log_admin_files = (char **) malloc(n * sizeof (char *));
  276.     start = LOG_ADMIN_FILES;
  277.     n = 0;
  278.     do {
  279.         log_admin_files[n++] = start;
  280.         if (!(p = strchr(start, ',')))
  281.         break;
  282.         *p = '\0';
  283.         start = p + 1;
  284.     } while (*start);
  285.     }
  286.     nr_log_admin_files = n;
  287. #endif
  288. }
  289.